package com.tchy.cloud.controller;

import com.tchy.cloud.entity.AConsultantVodEntity;
import com.tchy.cloud.entity.AConsultantVodRecordEntity;
import com.tchy.cloud.entity.TSCityEntity;
import org.apache.log4j.Logger;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.common.service.CommonService;
import org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.tag.vo.datatable.SortDirection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 直播信息维护
 */
@Controller
@RequestMapping("/recordController")
public class VodRecordController {
    private static final Logger logger = Logger.getLogger(AConsultantVodRecordEntity.class.getName());

    @Autowired
    private CommonService commonService;

    /**
     * 录播视频信息列表页面跳转
     *
     * @return
     */
    @RequestMapping(params = "index")
    public ModelAndView index() {
        return new ModelAndView("clound/record/index");
    }

    /**
     * 录播视频信息列表数据展示
     *
     * @param record
     * @param request
     * @param response
     * @param dataGrid
     */
    @RequestMapping(params = "datagrid")
    public void datagrid(AConsultantVodRecordEntity record, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery(AConsultantVodRecordEntity.class, dataGrid);
        cq.addOrder("vid", SortDirection.desc);
        cq.add();
        // 查询条件组装
        HqlGenerateUtil.installHql(cq, record, request.getParameterMap());
        commonService.getDataGridReturn(cq, true);
        TagUtil.datagrid(response, dataGrid);
    }

    /**
     * 查看
     *
     * @param record
     * @param req
     * @return
     */
    @RequestMapping(params = "detail")
    public ModelAndView detail(AConsultantVodRecordEntity record, HttpServletRequest req) {
        String id = req.getParameter("id");
        if (id != null) {
            record = commonService.getEntity(AConsultantVodRecordEntity.class, Long.valueOf(id));
        }
        req.setAttribute("record", record);
        return new ModelAndView("clound/record/detail");
    }
//
//
//    /**
//     * 新增及修改的数据处理
//     * @param aBankEntity
//     * @return
//     */
//    @RequestMapping(params = "saveorupdate", method = RequestMethod.POST)
//    @ResponseBody
//    public AjaxJson saveorupdate(ABankEntity aBankEntity) {
//        AjaxJson j = new AjaxJson();
//        try {
//            if (aBankEntity.getId() != null) {//修改
//                ABankEntity entity = commonService.get(ABankEntity.class, aBankEntity.getId());
//                MyBeanUtils.copyBeanNotNull2Bean(aBankEntity, entity);
//                commonService.saveOrUpdate(entity);
//            } else {//保存
//                commonService.save(aBankEntity);
//            }
//            j.setMsg("操作成功");
//        } catch (Exception e) {
//            logger.error(e);
//            j.setMsg("操作失败");
//        }
//        return j;
//    }

    /**
     * 删除
     *
     * @param record
     * @return
     */
    @RequestMapping(params = "del", method = RequestMethod.POST)
    @ResponseBody
    public AjaxJson del(AConsultantVodRecordEntity record, HttpServletRequest request) {
        String vid = request.getParameter("id");
        AjaxJson j = new AjaxJson();
        try {
            if (vid != null) {//删除
                AConsultantVodRecordEntity entity = commonService.get(AConsultantVodRecordEntity.class, Long.valueOf(vid));
                commonService.delete(entity);
                j.setMsg("操作成功");
            } else {//主键不存在
                j.setMsg("视频不存在，请重试。");
            }

        } catch (Exception e) {
            logger.error(e);
            j.setMsg("操作失败");
        }

        return j;
    }

}







